from matchme.models import Thought
from django.contrib.auth.models import User
import json

def getAllThoughts(response_format='json'):
	thoughts = Thought.objects.all()
	x={'thoughts':[]}
	for i in thoughts:
		x['thoughts'].append({'user':i.user.username,'thought':i.thought,'time':i.time_added.isoformat()})
	if response_format=='json':
		return json.dumps(x)
	

def getUserThoughts(user,response_format='json'):
	thoughts = Thought.objects.filter(user=user)
	x={'thoughts':[]}
	for i in thoughts:
		x['thoughts'].append({'thought':i.thought,'time':i.time_added.isoformat()})
	if response_format=='json':
		return json.dumps(x)
		
